﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddActivity.aspx.cs" Inherits="ZX.WebApp.Crm.Customer.AddActivity" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/extend.validate.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.calendar.js" type="text/javascript"></script>
    <link href="../../Styles/default/calendar.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="fieldTable">
            <tr>
                <td width="100">联系人：<span style="color: Red">*</span></td>
                <td>
                    <asp:DropDownList ID="LinkManID" runat="server" AppendDataBoundItems="true" Width="160">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>动作类型：<span style="color: Red">*</span></td>
                <td>
                    <asp:DropDownList ID="TypeID" runat="server" AppendDataBoundItems="true" Width="160">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr style="display:none;">
                <td>开始时间：<span style="color: Red">*</span></td>
                <td>
                    <input runat="server" type="text" id="PlanStartDate" name="PlanStartDate" style="width:100px;" />

                    <asp:DropDownList ID="ddlStartMin" runat="server">
                        </asp:DropDownList>
                        <b>:</b>
                        <asp:DropDownList ID="ddlStartSec" runat="server">
                        </asp:DropDownList>
                </td>

            </tr>
            <tr style="display:none;">
                <td>结束时间：<span style="color: Red">*</span></td>
                <td>
                    <input runat="server" type="text" id="PlanEndDate" name="PlanEndDate" style="width:100px;" />

                        <asp:DropDownList ID="ddlEndMin" runat="server">
                        </asp:DropDownList>
                        <b>:</b>
                        <asp:DropDownList ID="ddlEndSec" runat="server">
                        </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>过程描述：<span style="color: Red">*</span></td>
                <td>
                    <textarea id="Contents" name="Contents" title="(0-200)字"
                        onKeyDown="showSetNum('Contents','ShowContents',200)" 
                        onKeyUp="showSetNum('Contents','ShowContents',200)" 
                        onblur="showSetNull('ShowContents')"
                        style="width:280px; height:120px;"></textarea>
                    <span class="span_font" id="ShowContents"></span>
                </td>
            </tr>
            <tr style="display:none;">
                <td>备注：</td>
                <td>
                    <textarea id="Explain" name="Explain" title="(0-200)字"
                        onKeyDown="showSetNum('Explain','ShowExplain',200)" 
                        onKeyUp="showSetNum('Explain','ShowExplain',200)" 
                        onblur="showSetNull('ShowExplain')"
                        style="width:280px; height:40px;"></textarea>
                    <span class="span_font" id="ShowExplain"></span>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
<script type="text/javascript">
    var CustomerId = "<%=CustomerID %>", strLocalDate = "<%=LocalDate %>";
    var instance = [{ "LinkManID": "", "TypeID": "", "PlanStartDate": "", "PlanEndDate": "", "Contents": "", "Explain": ""}];
    $(document).ready(function () {
        $("#PlanStartDate").cld();
        $("#PlanEndDate").cld();
        $("#ddlStartMin").get(0).selectedIndex = 1;
        $("#ddlStartSec").get(0).selectedIndex = 1;
        $("#ddlEndMin").get(0).selectedIndex = 23;
        $("#ddlEndSec").get(0).selectedIndex = 59;
    });
    function Save() {
        instance[0].LinkManID = $("#LinkManID").val();
        instance[0].TypeID = $("#TypeID").val();
        instance[0].PlanStartDate = $("#PlanStartDate").val();
        instance[0].PlanEndDate = $("#PlanEndDate").val();
        instance[0].Contents = $("#Contents").val().replace(/(^\s*)|(\s*$)/g, '');
        instance[0].Explain = $("#Explain").val().replace(/(^\s*)|(\s*$)/g, '');
        if (instance[0].LinkManID == "") {
            alert("联系人不能为空!");
            $("#LinkManID").focus();
            return;
        }
        if (instance[0].TypeID == "") {
            alert("动作类型不能为空!");
            $("#TypeID").focus();
            return;
        }
        if (instance[0].PlanStartDate == "") {
            alert("开始时间不能为空!");
            $("#PlanStartDate").focus();
            return;
        }
        if (instance[0].PlanEndDate == "") {
            alert("结束时间不能为空!");
            $("#PlanEndDate").focus();
            return;
        }
        if (instance[0].Contents == "") {
            alert("描述不能为空!");
            $("#Contents").focus();
            return;
        }
        var fsm = $("#ddlStartMin").val();
        var fss = $("#ddlStartSec").val();
        var fem = $("#ddlEndMin").val();
        var fes = $("#ddlEndSec").val();
        if ($('#PlanEndDate').val() > strLocalDate) {
            alert("工作记录时段存在误填");
            $('#PlanEndDate').focus();
            return false;
        }
        if ($('#PlanStartDate').val() > $('#PlanEndDate').val()) {
            alert("结束时间不能小于开始时间");
            $('#PlanEndDate').focus();
            return;
        }
        if ($('#PlanStartDate').val() == $('#PlanEndDate').val()) {
            if (fsm > fem || (fsm == fem && fss >= fes)) {
                alert("结束时间不能小于开始时间");
                $('#PlanEndDate').focus();
                return;
            }
        }
        if (CustomerId != "") {
            instance[0].CustomId = CustomerId;
            instance[0].PlanStartDate = instance[0].PlanStartDate + " " + fsm + ":" + fss;
            instance[0].PlanEndDate = instance[0].PlanEndDate + " " + fem + ":" + fes;
            var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
            SaveData(json);
        } else {
            alert("客户ID为空,保存失败！");
            return;
        }
    }
    function SaveData(obj) {
        YAHOO.util.Connect.asyncRequest('POST', '../../Extend/AjaxData/CustomOperating.aspx?action=insert&entity=CrmActivity&json=' + encodeURI(obj), {
            success: function (res) {
                var inventory;
                try {
                    inventory = res.responseText;
                    if (inventory == "1") {
                        alert("保存成功!");
                        //location.reload(false);
                        parent.LoadActivity();
                    } else {
                        alert(inventory);
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
</script>
</html>
